#include <iostream>

#include <pthread.h>

namespace LockMutex
{
    class mutex
    {
    public:
        mutex(const mutex &) = delete;
        const mutex &operator=(const mutex &) = delete;
        mutex()
        {
            int n = pthread_mutex_init(&_mutex, nullptr);
            (void)n;
        }
        ~mutex()
        {
            int n = pthread_mutex_destroy(&_mutex);
            (void)n;
        }
        void Lock()
        {
            int n = pthread_mutex_lock(&_mutex);
            (void)n;
        }
        void Unlock()
        {
            int n = pthread_mutex_unlock(&_mutex);
            (void)n;
        }
        pthread_mutex_t *LockPtr()
        {
            return &_mutex;
        }

    private:
        pthread_mutex_t _mutex;
    };

    class LockGurd
    {
    public:
        LockGurd(mutex &mtx) : _mtx(mtx)
        {
            _mtx.Lock();
        }
        ~LockGurd()
        {
            _mtx.Unlock();
        }

    private:
        mutex &_mtx;
    };
}